<?php
class AdController extends RestController
{
	/**
	 * 获取手机广告位
	 */
	public function actionIndex()
    {
    	if(MOBILEOS==='android')
    	{
    		//安卓手机广告
			$key     = 'MOBILE_AD';
			$adTitle = '手机广告位';
    	}
    	else
    	{
    		//ios手机广告位
    		$key     = 'MOBILE_AD_IOS';
			$adTitle = 'ios广告位';
    	}
    	$data    = Yii::app()->cache2->get($key);
		if($data == false)
		{
			$data = array();
			$cate = AdCate::model()->find('title=:title', array(':title'=>$adTitle));
			if($cate !== null)
			{
				$ads    = Ad::model()->findAll(array(
						'condition' => 'cate_id='.$cate->id.' and status=1',
						'order' => 'sort desc',
					));
				foreach($ads as $k=>$ad)
				{
					$data[$k]['img']  = Yii::app()->params['UpYun']['visitUrl'].$ad->img;
					$data[$k]['link'] = $ad->link;
					$data[$k]['title']= $ad->title;
				}
				Yii::app()->cache2->set($key,json_encode($data));
			}
		}else{
			$data = json_decode($data);
		}
		$this->setResult($data);
	}
}
